
#ifndef PING_H_
#define PING_H_

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <signal.h>
#include <errno.h>
#include <malloc.h>

#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <netinet/ip6.h>
#include <netinet/icmp6.h>


#define BUFFER_SIZE 1500

// static char sendbuffer[BUFFER_SIZE];

// static int datalen = 56;
// static int nsent;
// static int sockfd;
// static int verbose;

// static char * host;
// static pid_t pid;

void init_v6(void);
void proc_v6(char * buffer, ssize_t size, struct msghdr * msg, struct timeval * time);
void proc_v4(char * buffer, ssize_t size, struct msghdr * msg, struct timeval * time);

void send_v4(void);
void send_v6(void);

void readloop(void);

void sig_alarm(int);
void tv_sub(struct timeval * out, struct timeval * in);

uint16_t in_sksum(uint16_t * addr, int len);

struct proto {

    void (*fptoc)(char *, ssize_t, struct msghdr * , struct timeval * );
    void (*fsend)(void);
    void (*finit)(void);

    struct sockaddr * sasend;
    struct sockaddr * sarecv;

    socklen_t   salen;
    int         icmpproto;
};

typedef struct PingInstance {

    struct proto * pr;
    int datalen;
    int nsend;
    int sockfd;
    char buffer[BUFFER_SIZE];
    int verbose;
    pid_t pid;
    char * host;
}PingInstance;

PingInstance * Instance();

#endif // !PING_H_
